﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;

namespace MishraReader.Controls
{
    public class BindableButton : Button
    {
        static BindableButton()
        {
            CommandParameterProperty.OverrideMetadata(typeof(BindableButton), new FrameworkPropertyMetadata(OnCommandParameterChanged));
        }

        private static readonly MethodInfo InvokeUpdate = typeof(ButtonBase).GetMethod("UpdateCanExecute", BindingFlags.Instance | BindingFlags.NonPublic);
        

        private static void OnCommandParameterChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var button = d as BindableButton;

            if(d != null)
            {
                InvokeUpdate.Invoke(button, null);
            }
        }
    }
}
